/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package interfaz;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.JTextField;

/**
 *
 * @author Maya
 */
public class CampoNumerico {

     public void validarCampo(JTextField textField){
        textField.addKeyListener(new KeyAdapter(){
            @Override
           public void keyTyped(KeyEvent e)
           {
              char caracter = e.getKeyChar();

              // Verificar si la tecla pulsada no es un digito
              if(((caracter < '0') ||
                 (caracter > '9')) &&
                 (caracter != KeyEvent.VK_BACK_SPACE))
              {
                 e.consume();  // ignorar el evento de teclado
              }
           }
        });
    }

}
